<?php
/**
 * User: 五哥派
 * Date: 2024/7/17
 * Tel(同WX): 17335592719
 */
namespace app\api\controller\v1;

use app\api\controller\ApiBase;
use app\api\service\auth\Login as LoginService;

class Auth extends ApiBase
{

    public function verifyToken($token=''){
        if(!$token){
            return error('不存在，重新获取!');
        }
        $valid = LoginService::verifyMpWxToken($token);
        if(!$valid){
            return error('不存在，重新获取!');
        }

        return success('存在!');
    }



    /**
     * 微信小程序快捷登录 (提交wx.login接口返回的code)
     */
    public function getToken()
    {
        $LoginService = new LoginService;
        if (!$LoginService->loginMpWx($this->postForm())) {
            return error($LoginService->getError());
        }
        // 获取登录成功后的用户信息
        $userInfo = $LoginService->getUserInfo();
        $token = $LoginService->getToken();
        return success('登录成功', [
            'userInfo' => $userInfo,
            'token' => $token
        ]);
    }





}